package com.mxx.common.data.utils;

import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

/**
 * @Author itzgyw
 * @Date 2020-01-29
 * @Time 17:01
 * @Description:
 */
public class MongoUtil {

    public static Update getUpdate() {
        return new Update();
    }

    public static Update getUpdate(String key, Object val) {
        return getUpdate().set(key, val);
    }

    public static Query getQuery(Criteria criteria) {
        return getQuery().addCriteria(criteria);
    }

    public static Query getQuery() {
        return new Query();
    }

    public static Object getId(Object id) {
        String strId = String.valueOf(id);
        return id == null ? null : ObjectId.isValid(strId) ? new ObjectId(strId) : id;
    }


}
